


use jbpa_replication, clear


// figure 1

hist allosd, width(100) fraction ///
	scheme(538) ///
	bcolor(538b) ///
	ytitle("Percent of distribution-instances", margin(right)) ///
	xtitle("Standard deviation of distribution-instance", margin(top)) ///
	name(histsd, replace) ///
	saving(histsd, replace)
	
	 
 // figure 2.  
 /*To make the figure readable, the -if inrange- statement is used to 
 show scatter without the very few (n = 160) distribution-instances with 
 variation > 2,000.  Findings don't change without the -if inrange- statement, but
 the graph becomes much less legible. */  
 
 twoway ///
 (scatter allosd demohet, m(c) msize(tiny) mc(538b) jitter()) ///
 (lfit allosd demohet, lc(538r) lw(medium)) ///
	if inrange(allosd,0,2000)  ///
 , ///
 xlabel(0 0.2 0.4 0.6 0.75 0.8) ///
 xtitle("Group diversity", margin(top)) ///
 ytitle("Standard deviation of awards", margin(right)) ///
 name(demobyallo, replace) ///
 legend(off) ///
 scheme(538)
 

 
 
 
 // figure 3
 twoway ///
 (scatter allosd grpsize, m(oh) msize(vtiny) mc(538b) jitter(3)) ///
 (lfit allosd grpsize, lc(538r) lw(medium)) ///
	if inrange(grpsize,5,20) & inrange(allosd,0,2000) ///
 , ///
 legend(off) ///
 xtitle("Group size", margin(top)) ///
 xlabel(5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20) ///
 xscale(range(4.7 20.3)) ///
 ytitle("Standard deviation of awards", margin(right)) ///
 scheme(538) ///
 name(sizebyallo, replace)
 
 
 

 // figure 4
/* generating clusters. Figure produced may differ randomly from figure in text,
since clustering needs an arbitrary starting point (a random seed), to be 
entered in -krandom- option below */

local agencies  AG CM DJ DL DN ED EP HE HS HU IN NN ST TD TR VA
foreach agy of local agencies {
di "`agy'"
capture noisily {
cluster kmeans occhet edlevhet sal_sd time_sd ///
	gov_sd grpsize  if agy=="`agy'" & year==2013, ///
	start(krandom(6666)) k(2) gen(`agy'_clus_2013)
	}
}
 
* generating x-axis numbers so that within agencies, clusters are offset 
gen cabagynumleft = 0
local i = 1
local agencies  AG CM DJ DL DN ED EP HE HS HU IN NN ST TD TR VA
foreach agy of local agencies {
replace cabagynumleft = `i' - .2 if agy=="`agy'"
local ++i
local ++i
local i = `i' + .5
}

gen cabagynumright = 0
local i = 1
local agencies  AG CM DJ DL DN ED EP HE HS HU IN NN ST TD TR VA
foreach agy of local agencies {
replace cabagynumright = `i' + .2 if agy=="`agy'"
local ++i
local ++i
local i = `i' + .5
}

 
 
 
scatter allosd cabagynumleft if AG_clus_2013==1 & allosd < 2000, m(circle) msize(*.13) mcolor(538b) jitter(4) /// 
|| ///
scatter allosd cabagynumleft if CM_clus_2013==1, m(circle) msize(*.13) mcolor(538b) jitter(4) ///
|| ///
scatter allosd cabagynumleft if DJ_clus_2013==1, m(circle) msize(*.13) mcolor(538b) jitter(4) ///
|| ///
scatter allosd cabagynumleft if DL_clus_2013==1, m(circle) msize(*.13) mcolor(538b) jitter(4) ///
|| ///
scatter allosd cabagynumleft if DN_clus_2013==1, m(circle) msize(*.13) mcolor(538b) jitter(4) ///
|| ///
scatter allosd cabagynumleft if ED_clus_2013==1, m(circle) msize(*.13) mcolor(538b) jitter(4) ///
|| ///
scatter allosd cabagynumleft if EP_clus_2013==1, m(circle) msize(*.13) mcolor(538b) jitter(4) ///
|| ///
scatter allosd cabagynumleft if HE_clus_2013==1, m(circle) msize(*.13) mcolor(538b) jitter(4) ///
|| ///
scatter allosd cabagynumleft if HS_clus_2013==1, m(circle) msize(*.13) mcolor(538b) jitter(4) ///
|| ///
scatter allosd cabagynumleft if HU_clus_2013==1, m(circle) msize(*.13) mcolor(538b) jitter(4) ///
|| ///
scatter allosd cabagynumleft if IN_clus_2013==1, m(circle) msize(*.13) mcolor(538b) jitter(4) ///
|| ///
scatter allosd cabagynumleft if NN_clus_2013==1, m(circle) msize(*.13) mcolor(538b) jitter(4) ///
|| ///
scatter allosd cabagynumleft if ST_clus_2013==1, m(circle) msize(*.13) mcolor(538b) jitter(4) ///
|| ///
scatter allosd cabagynumleft if TD_clus_2013==1, m(circle) msize(*.13) mcolor(538b) jitter(4) ///
|| ///
scatter allosd cabagynumleft if TR_clus_2013==1, m(circle) msize(*.13) mcolor(538b) jitter(4) ///
|| ///
scatter allosd cabagynumleft if VA_clus_2013==1 & allosd < 2000, m(circle) msize(*.13) mcolor(538b) jitter(4) ///
|| ///
scatter allosd cabagynumright if AG_clus_2013==2, m(circle) msize(*.13) mcolor(538o) jitter(4) /// 
|| ///
scatter allosd cabagynumright if CM_clus_2013==2, m(circle) msize(*.13) mcolor(538o) jitter(4) ///
|| ///
scatter allosd cabagynumright if DJ_clus_2013==2, m(circle) msize(*.13) mcolor(538o) jitter(4) ///
|| ///
scatter allosd cabagynumright if DL_clus_2013==2, m(circle) msize(*.13) mcolor(538o) jitter(4) ///
|| ///
scatter allosd cabagynumright if DN_clus_2013==2, m(circle) msize(*.13) mcolor(538o) jitter(4) ///
|| ///
scatter allosd cabagynumright if ED_clus_2013==2, m(circle) msize(*.13) mcolor(538o) jitter(4) ///
|| ///
scatter allosd cabagynumright if EP_clus_2013==2, m(circle) msize(*.13) mcolor(538o) jitter(4) ///
|| ///
scatter allosd cabagynumright if HE_clus_2013==2, m(circle) msize(*.13) mcolor(538o) jitter(4) ///
|| ///
scatter allosd cabagynumright if HS_clus_2013==2, m(circle) msize(*.13) mcolor(538o) jitter(4) ///
|| ///
scatter allosd cabagynumright if HU_clus_2013==2, m(circle) msize(*.13) mcolor(538o) jitter(4) ///
|| ///
scatter allosd cabagynumright if IN_clus_2013==2, m(circle) msize(*.13) mcolor(538o) jitter(4) ///
|| ///
scatter allosd cabagynumright if NN_clus_2013==2, m(circle) msize(*.13) mcolor(538o) jitter(4) ///
|| ///
scatter allosd cabagynumright if ST_clus_2013==2, m(circle) msize(*.13) mcolor(538o) jitter(4) ///
|| ///
scatter allosd cabagynumright if TD_clus_2013==2, m(circle) msize(*.13) mcolor(538o) jitter(4) ///
|| ///
scatter allosd cabagynumright if TR_clus_2013==2, m(circle) msize(*.13) mcolor(538o) jitter(4) ///
|| ///
scatter allosd cabagynumright if VA_clus_2013==2 & allosd < 2000, m(circle) msize(*.13) mcolor(538o) jitter(4) ///
, xlabel(1 "Agriculture" 3.5 "Commerce" 6 "Justice" 8.5 "Labor" ///
	11 "Energy" 13.5 "Education" 16 "EPA" 18.5 "Health & Human" 21 "Homeland" ///
	23.5 "HUD" 26 "Interior" 28.5 "NASA" 31 "State" ///
	33.5 "Transportation" 36 "Treasury" 38.5 "Veterans Affairs", angle(45) labsize(small)) ///
xscale(range(0 40)) ///
xtitle("") ///
ylabel(0 "$0" 500 "$500" 1000 "$1,000" 1500 "$1,500" 2000 "$2,000") ///
ytitle("Intra-group variation in reward sizes (standard deviation)", margin(right)) ///
legend(off) ///
scheme(538)
 
 
 
 
// figure 5

twoway ///
 (scatter allosd super_years, m(point) msize() mc(538b%100) jitter(5)) ///
 (lfit allosd super_years, lc(538r%80) lw(medium)) ///
	if inrange(allosd,0,2000) ///
 , ///
 xtitle("Supervisor years of experience", margin(top)) ///
 ytitle("Standard deviation of awards", margin(right)) ///
 legend(off) ///
 name(experbyallo, replace) ///
 scheme(538) 
 
 
 
